const {db} = require('../util/util')

const getUsers = () => {
    const sql = "SELECT * FROM user"
    return db.execute(sql)
}

const getUserByAddress = (address) => {
    const sql = "SELECT * FROM user WHERE address = ?"
    return db.execute(sql, [address])
}

const addUser = (address, words) => {
    const sql = 'INSERT INTO user (address, words) VALUES (?, ?)'
    return db.execute(sql, [address, words])
}

const deleteUser = (_id) => {
    const sql = 'DELETE FROM user WHERE _id = ?'
    return db.execute(sql, [_id])
}

const updateUser = (user) => {
    const sql = 'UPDATE user SET address = ?, words = ? WHERE _id = ?'
    return db.execute(sql, [user.address, user.words, user._id])
}
module.exports = {getUsers, addUser, deleteUser, updateUser, getUserByAddress}